<?php
include "../../common.php";

// подключаемся к базе данных
$db = new DB();
$db->SetConfig($cfg['db']);
$db->SetTables($cfg['tables']);
$db->Connect();

//{{{ Паараметры от пользователя

$query = isset($_GET['query']) ? $_GET['query'] : '';
$type = isset($_GET['type']) ? $_GET['type'] : '';


//}}}
// Результаты поиска
$search_result = array();
$result = (object) array(
			'query' => $query,
			'suggestions' => $search_result
);

if ( !$query )
{
	print json_encode($result);
}

$search = new ProfessionSearch($db);
$list = $search->GetByFilters(array(
	'where' => "`profession`.`title` LIKE '%" . $query . "%'"
		));

if ( $list )
{
	foreach ($list as $k => $v)
	{
		$search_result[] = $v->GetName();
	}
}

print json_encode($result);
?>